#include "head.h"

/*
Usage:创建服务器的socket
*/

int initTcpLink(int *socket_fd,char *ip,char *port){
    int ret_socket_create;
    ret_socket_create = socket(AF_INET,SOCK_STREAM,0);
    ERROR_CHECK(ret_socket_create,-1,"server socket create");
    *socket_fd = ret_socket_create;

    int reuse = 1;
    setsockopt(*socket_fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse));

    struct sockaddr_in addr;
    addr.sin_family = AF_INET;
    addr.sin_addr.s_addr = inet_addr(ip);
    addr.sin_port = htons(atoi(port));

    bind(*socket_fd,(struct sockaddr*)&addr,sizeof(addr));
    listen(*socket_fd,10);

    return 0;
}
